<%@ page language="java" contentType="text/html; charset=UTF-8"	 pageEncoding="UTF-8"%>
<%@ include file="../include/laypublic.jsp"%>
<!DOCTYPE html>
<html>
<head>
  <title>小微评审复制</title>
</head>
<style>
	.fieldset{
		margin-top: 5px;
		margin-bottom: 0px
	}
	.layui-legend{
		background-color:#5fb878;
		font-size:15px !important;
		width:140px;
	}
	.layui-form-item {
	    margin-bottom: 5px;
	    clear: both;
	    *zoom: 1;
	}
	.layui-form-label{width: 180px;}
</style>
<body>
	<div class="layui-fluid">
		<div class="layui-card">
			<div style="padding-top: 15px;">&nbsp;</div>
			<form class="layui-form" id="addInfo_form" lay-filter="addInfo_form">
				<div class="layui-tab layui-tab-brief" >
					<div class="layui-tab-content">
						<div class="layui-tab-item layui-show">
							
							<fieldset class="layui-elem-field layui-field-title fieldset" id="baseInfo" >
								<legend class="layui-btn layui-legend"
									style="text-align: left; cursor: default;" >项目基础信息 ></legend>
								<div class="layui-form-item">
									<div class="layui-inline">
										<label class="layui-form-label">申请公司</label>
										<div class="layui-input-inline">
											<input type="hidden" name="hrOrgid" value="${bindOrgId}">
											<input type="text" value="${bindOrgName}"
												style="border: 0px;" readonly="readonly" class="layui-input">
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label">申请部门</label>
										<div class="layui-input-inline">
											<input type="hidden" name="hrDeptid" value="${bindDeptId}">
											<input type="text" value="${bindDeptName}"
												style="border: 0px;" readonly="readonly" class="layui-input">
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label">申请人</label>
										<div class="layui-input-inline">
											<input type="hidden" name="hrStaffApplyid"
												value="${SESSION_KEY_USER_DETAIL.hrStaffId }"> <input
												type="text" name="staffname" value="${SESSION_KEY_USER_DETAIL.realName }"
												readonly="readonly" style="border: 0px" autocomplete="off"
												class="layui-input">
										</div>
									</div>
								</div>
								<div class="layui-form-item">
									<div class="layui-inline">
										<label class="layui-form-label">项目名称</label>
										<div class="layui-input-inline">
											<input type="text" name="proNames" value="${microExamVo.proName}" 
												style="border:0px;width:265px" readonly="readonly" class="layui-input">
											<input type="hidden" name="proCodeAndCodes" value="${microExamVo.proCode}_${microExamVo.id}_${microExamVo.proName}"
												style="border:0px;width:220px" readonly="readonly" class="layui-input">
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label">实施机构</label>
										<div class="layui-input-inline">
											<input type="text" value="${microExamVo.carryOrg}" id="id_ImplementingBody" name="carryOrg" style="border: 0px;"
												readonly="readonly" class="layui-input">
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label">区域公司</label>
										<div class="layui-input-inline">
											<input type="text" value="${microExamVo.orgAreaName}" id ="query-input-hrOrgAreName" style="border: 0px;width:220px" 
										 		 readonly="readonly" class="layui-input">
											<input type="hidden" name="hrOrgAreaId" value="${microExamVo.hrOrgAreaId}" id ="query-input-hrOrgAreName" style="border: 0px;width:220px" 
										 		 readonly="readonly" class="layui-input">
										</div>
									</div>
								</div>
								<div class="layui-form-item">
									<div class="layui-inline">
										<label class="layui-form-label">项目负责人</label>
										<div class="layui-input-inline">
											<input type="hidden" id="hrOrgProId" name="hrOrgProId" value="">
											<input type="text" value="${microExamVo.proLeader}" id="id_projectLeader" name="proLeader" style="border: 0px;"
												readonly="readonly" maxlength="10" lay-verify="required|COC"
												class="layui-input">
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label">工程地址</label>
										<div class="layui-input-inline">
											<input type="hidden" id="sgCityId" name="sgCityId" value="${microExamVo.sgCityId}">
											<input type="text" value="${microExamVo.sgCityName}" id="id_projectAddress" name="projectAddress" value=""
												style="border: 0px;" readonly="readonly" class="layui-input">
										</div>
									</div>
								</div>												
							</fieldset>						
							<fieldset class="layui-elem-field layui-field-title fieldset" id="contractPriceInfo" >
								<legend class="layui-btn layui-legend" style="text-align: left; cursor: default;" >小微评审信息 ></legend>
								<div class="layui-form-item">
									<div class="layui-inline">
										<label class="layui-form-label" >小微利润金额(元)</label>
										<div class="layui-input-inline">
											<input type="text" value="${microExamVo.microProfitAmount}" maxlength="13" lay-verify="required|floatNumber" id="Id_microProfitAmount" 
											name="microProfitAmount" placeholder="请输入小微利润金额" autocomplete="off" 
											onblur="isNumberAndFloat1(this);arabiaToCN(this,1);" class="layui-input" >
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label">利润率(%)</label>
										<div class="layui-input-inline">
											<input type="text" value="${microExamVo.profitRate}" lay-verify="required|floatNumber" id="Id_profitRate" 
											name="profitRate" placeholder="请输入利润率" autocomplete="off" 
											onblur="isNumberAndFloat1(this);" class="layui-input" >
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label">扭亏金额(元)</label>
										<div class="layui-input-inline">
											<input type="text" value="${microExamVo.stopLossAmount}" maxlength="13" lay-verify="required|floatNumber" id="Id_stopLossAmount" 
											name="stopLossAmount" placeholder="请输入扭亏金额" autocomplete="off" 
											onblur="isNumberAndFloat1(this);arabiaToCN(this,1);" class="layui-input" >
										</div>
									</div>
								</div>									
								<div class="layui-form-item">
									<div class="layui-inline">
										<label class="layui-form-label" >测算及边界条件说明</label>
										<div class="layui-input-inline">
											<textarea id="id_borderMemo" placeholder="请输入测算及边界条件说明" name="borderMemo"
											class="layui-textarea" lay-verify="required" maxlength="2000"
											style="width: 899px; height: 90px;">${microExamVo.borderMemo }</textarea>
										</div>
									</div>
								</div>																											
							</fieldset>						
						</div>
					</div>
				</div>

				<div class="layui-form-item"
					style="position: fixed ! important; right: 30px; bottom: 45%; z-index: 10000;">
					<div class="layui-input-block">
						<button
							class="layui-btn layui-bg-blue layui-btn-normal layui-btn-lg  layui-btn-radius"
							type="button" lay-submit lay-filter="addInfo_form_submit"
							id="addInfo_form_submit">
							<i class="layui-icon layui-icon-ok layuiadmin-button-btn"></i> 提交
						</button>
					</div>
				</div>
			</form>
		</div>
	</div>
</body>
</html>
<script type="text/javascript">
	var proName;
	var proNameid;
	//静态资源路径前缀
	var staticPath = '${fileHttpPre}';
	var stateJSON = <infopub:dicJson groupNo="A00010028" />;
	layui.config({
	    base: '${ctx}/resources/layuiadmin/' //静态资源所在路径
	  }).extend({
	    index: 'lib/index' //主入口模块
	  }).use(['index', 'set', 'upload', 'element', 'laydate'], function(){
	    var $ = layui.$
	    ,form = layui.form
	    ,element = layui.element
	    ,laydate = layui.laydate
	    ,upload = layui.upload;
		// 正则校验
		form.verify({
			//验证汉字
		    CHS:[
		    	/^[\u0391-\uFFE5]+$/
		    	,'只能输入汉字'
		  	],
		  	//名字校验
		  	COC: [
				/^[\u4e00-\u9fa5_a-zA-Z0-9]+$/
				,'请输入正确的名称'
		  	],
		  	//大于0的正整数
		  	intNumber:[
				/^[1-9]\d*$/
				,'请输入正确的数字'
		  	],
		  	//数字只能有两位小数
		  	floatNumber:[
				/^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
				,'请输入正确的数字'
		  	],
		  	telNumber:[/^[1][3,4,5,7,8,9][0-9]{9}$/
				  		,'请输入正确的号码'
			],
		  	//数字大于0，并只能有两位小数
		  	floatAmount:[
				/^([1-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
				//var pattern=/^((\d+\.\d*[1-9]\d{1})|(\d*[1-9]\d*\.\d{2}))$/; 
				,'请输入正确的数字'
		  	]
		});
		form.on('select(add_select_proId)', function(data) {
			var id = data.value;
			proNameid = data.value;
			proName = data.elem.getAttribute('proName');
	
			if(id==''||id==null){
	    		layer.msg('请选择项目名称',{icon: 1});
	    		return;
	    	}else{
	    		getMicroExamByProCode(id); 
	    	}	
		});
		
		form.on('submit(addInfo_form_submit)', function(data) {
			$("#addInfo_form_submit").removeAttr("lay-submit").removeClass("layui-bg-blue").addClass("layui-btn-disabled");
			//提交 Ajax 成功后，静态更新表格中的数据
               $.ajax({
                   type : 'post',
         		   url : basePath + '/microExam/save',
                   data: $('#addInfo_form').serialize(),
         		   success:function(result){
         				if(result.success){
         					layer.closeAll('loading'); //关闭loading
         					layer.msg('提交单据成功~',{icon: 1});
         					//两秒后关闭当前页面
         					setTimeout(function(){
         						/**
         						 * 查找父菜单，并刷新
         						 */
         						var topDoc = $(window.top.document);
         						var path = basePath + '/microExam/list';
         						// 获取页面名称
         						var name = topDoc.find(".layui-nav-item [lay-href^='" + path + "']").text();
         						if(name == '' || name == null){
         							name = '小微评审';
         						}
         						window.parent.layui.index.openTabsPage(path, name);
         						var iframe = window.parent.layui.admin.tabsBody(window.parent.layui.admin.tabsPage.index).find(".layadmin-iframe");
         						iframe[0].contentWindow.location.reload(true);
         						
         						/**
         						 * 关闭当前页
         						 */
         						var currPath = basePath + '/microExam/toCopy';
         						var layid = topDoc.find("li[lay-id^='" + currPath + "']").attr('lay-id');
         						window.parent.layui.element.tabDelete('layadmin-layout-tabs', layid);//关闭当前页
         				        }, 2000);
         				}else{
         					layer.closeAll('loading'); //关闭loading
           					$("#addInfo_form_submit").removeClass("layui-btn-disabled").addClass("layui-bg-blue").attr("lay-submit","");
         					layer.msg(result.msg,{icon: 7});
         			  	}
         			}
              });
		});
	});
	//根据项目名称带出需要的小微评审字段
	function getMicroExamByProCode(id) {		
		var $ = layui.$, form = layui.form
		var proCodeAndCodes = id;
		$.ajax({
			type : "POST", //提交方式  
			url : "${ctx}/microExam/getMicroExamByProCode",//路径  
			data : {
				"proCodeAndCodes" : proCodeAndCodes
			},	//数据，这里使用的是Json格式进行传输  
			success : function(result) {	//返回数据根据结果进行相应的处理 
				if (result.flag == true) {
					if(result.microExamProCode!=null){
						$("#id_proCode")
								.attr("value", result.microExamProCode.proCode);//项目编号
						if (result.microExamProCode.orgAreaName != null) {
							$("#id_regionalCompany").attr("value",
									result.microExamProCode.orgAreaName);//区域公司
							$("#areaId").attr("value",
									result.microExamProCode.hrOrgAreaId);//区域公司id
						} else {
							$("#id_regionalCompany").attr("value", "暂时为空不可编辑");//区域公司
						}
						if (result.microExamProCode.hrOrgProId != null) {
							$("#hrOrgProId").attr("value",
									result.microExamProCode.hrOrgProId);//项目公司id											
						}
						$("#id_projectAddress").attr("value",
								result.microExamProCode.sgCityName);//工程地址
						$("#sgCityId").attr("value",
								result.microExamProCode.sgCityId);//工程地址城市id		
						$("#id_ImplementingBody").attr("value",
								result.microExamProCode.carryOrg);//实施机构
						$("#id_projectLeader").attr("value",
								result.microExamProCode.proLeader);//项目负责人
						
					}else{
						$("#id_proCode").attr("value", '');//项目编号
						$("#areaId").attr("value",'');//区域公司id
						$("#id_regionalCompany").attr("value", '');//区域公司
						$("#hrOrgProId").attr("value",'');//项目公司id
						$("#id_projectAddress").attr("value",'');//工程地址
						$("#sgCityId").attr("value",'');//工程地址城市id		
						$("#id_ImplementingBody").attr("value",'');//实施机构
						$("#id_projectLeader").attr("value",'');//项目负责人						
					}					
					form.render();
				}
			}
		});
	}
	var rgx = /^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/;
	// 校验需要输入数字的input框(请输入正确数字，且保留两位小数！)
	function isNumberAndFloat1(str) {
		var $ = layui.$
		if (str.value == '' || str.value == null) {
			return;
		}		
		var boolrgx = rgx.test(str.value);// true 
		if (boolrgx) {
			return true;
		} else {
			str.value =0;
			layer.msg('请输入正确数字，且保留两位小数！');
		}
	}
</script>